﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.Reflection.Emit;

namespace WPFInterview
{
    public class GridEventTest : IQuestion
    {
        public string TestName 
        { 
            get 
            { 
                return "WPF - Event"; 
            } 
        }

        public UserControl getUserControl()
        {
            return new GridEvent();
        }
    }


    /// <summary>
    /// Interaction logic for GridTest.xaml
    /// </summary>
    public partial class GridEvent : UserControl
    {
        // Define the event
        private event RoutedEventHandler _gridControl;

        public GridEvent()
        {
            InitializeComponent();
            _firstButton.Click += new RoutedEventHandler(_firstButton_Click);
            _secButton.Click += new RoutedEventHandler(_secButton_Click);

            // Register the event handler
            _gridControl += new RoutedEventHandler(_firstButton_Click);
            _gridControl += new RoutedEventHandler(_secButton_Click);
            // Trigger the event handler
            //_gridControl(this, new RoutedEventArgs());

            Assembly assemble = Assembly.GetCallingAssembly();

            assemble = Assembly.GetEntryAssembly();

            this._listAssemblies.Items.Clear();
            assemble = Assembly.GetExecutingAssembly();
            foreach(Module module in assemble.GetModules())
            {
                this._listAssemblies.Items.Add(module.Name);
            }

            foreach (Type type in assemble.GetTypes())
            {
                this._listAssemblies.Items.Add(type.Name);                
            }
        }

        void _secButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("First button is clicked");
        }

        void _firstButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Second button is clicked");
        }

        private void TreeView_Expanded(object sender, RoutedEventArgs e)
        {

        }
    }
}
